package com.generate;

import cn.smallbun.screw.core.Configuration;
import cn.smallbun.screw.core.engine.EngineConfig;
import cn.smallbun.screw.core.engine.EngineFileType;
import cn.smallbun.screw.core.engine.EngineTemplateType;
import cn.smallbun.screw.core.execute.DocumentationExecute;
import cn.smallbun.screw.core.process.ProcessConfig;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import javax.sql.DataSource;
import java.util.ArrayList;

public class DbDocGenerate {

    public static void main(String[] args) {
        {
            //数据源
            String dbip = "rm-wz9yzxv2pk1tfx721bo.mysql.rds.aliyuncs.com:3306/lute_os";
            if (args.length > 0) {
                dbip = args[0];
            }
            String user = "dev_lute";
            if (args.length > 1) {
                user = args[1];
            }
            String pwd = "Lute@123";
            if (args.length > 2) {
                pwd = args[1];
            }
            System.out.println("打印数据源: " + dbip + "  用户: " + user + "  的db文档！！！！！！");
            HikariConfig hikariConfig = new HikariConfig();
            hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
            hikariConfig.setJdbcUrl("jdbc:mysql://" + dbip);
            hikariConfig.setUsername(user);
            hikariConfig.setPassword(pwd);
            //设置可以获取tables remarks信息
            hikariConfig.addDataSourceProperty("useInformationSchema", "true");
            hikariConfig.setMinimumIdle(2);
            hikariConfig.setMaximumPoolSize(5);
            DataSource dataSource = new HikariDataSource(hikariConfig);
            //生成配置
            EngineConfig engineConfig = EngineConfig.builder()
                    //生成文件路径
                    .fileOutputDir("D:\\me\\sailors\\数据库文档")
                    //打开目录
                    .openOutputDir(true)
                    //文件类型
                    .fileType(EngineFileType.HTML)
                    //生成模板实现
                    .produceType(EngineTemplateType.freemarker).build();

            //忽略表
            ArrayList<String> ignoreTableName = new ArrayList<>();
            addIngnoreTableName(ignoreTableName);
            //忽略表前缀
            ArrayList<String> ignorePrefix = new ArrayList<>();
            // ignorePrefix.add("test_");
            //忽略表后缀
            ArrayList<String> ignoreSuffix = new ArrayList<>();
            //ignoreSuffix.add("_test");
            ProcessConfig processConfig = ProcessConfig.builder()
                    //忽略表名
                    .ignoreTableName(ignoreTableName)
                    //忽略表前缀
                    .ignoreTablePrefix(ignorePrefix)
                    //忽略表后缀
                    .ignoreTableSuffix(ignoreSuffix).build();
            //配置
            Configuration config = Configuration.builder()
                    //版本
                    .version("1.0.0")
                    //描述
                    .description("lute数据库文档20230804")
                    //数据源
                    .dataSource(dataSource)
                    //生成配置
                    .engineConfig(engineConfig)
                    //生成配置
                    .produceConfig(processConfig).build();
            //执行生成
            new DocumentationExecute(config).execute();
        }
    }

    private static void addIngnoreTableName(ArrayList<String> ignoreTableName) {/*
        ignoreTableName.add("Sheet1");
        ignoreTableName.add("a2b_connect_field_relative");
        ignoreTableName.add("a2b_connect_project");
        ignoreTableName.add("a2b_value_translate");
        ignoreTableName.add("bank_trade_detail");
        ignoreTableName.add("branch_table");
        ignoreTableName.add("canal_adapter_config");
        ignoreTableName.add("canal_cluster");
        ignoreTableName.add("canal_config");
        ignoreTableName.add("canal_instance_config");
        ignoreTableName.add("canal_node_server");
        ignoreTableName.add("canal_user");
        ignoreTableName.add("global_table");
        ignoreTableName.add("lock_table");
        ignoreTableName.add("loudong");
        ignoreTableName.add("pdman_db_version");
        ignoreTableName.add("t_glp_delivery");
        ignoreTableName.add("t_glp_delivery_goods");
        ignoreTableName.add("t_glp_entry");
        ignoreTableName.add("t_glp_entry_goods");
        ignoreTableName.add("t_glp_goods");
        ignoreTableName.add("t_glp_middle_delivery");
        ignoreTableName.add("t_glp_middle_delivery_goods");
        ignoreTableName.add("t_glp_middle_entry");
        ignoreTableName.add("t_glp_middle_entry_goods");
        ignoreTableName.add("t_glp_middle_goods");
        ignoreTableName.add("t_glp_stock_data");
        ignoreTableName.add("t_spdb_company");
        ignoreTableName.add("t_spdb_company_account");
        ignoreTableName.add("t_spdb_country_code");
        ignoreTableName.add("t_spdb_financing_pay_record");
        ignoreTableName.add("t_spdb_middle_company");
        ignoreTableName.add("t_spdb_middle_company_account");
        ignoreTableName.add("t_spdb_middle_order_sku");
        ignoreTableName.add("t_spdb_middle_purchase_order");
        ignoreTableName.add("t_spdb_middle_sale_order");
        ignoreTableName.add("t_spdb_middle_sku");
        ignoreTableName.add("t_spdb_order_sku");
        ignoreTableName.add("t_spdb_purchase_order");
        ignoreTableName.add("t_spdb_sale_order");
        ignoreTableName.add("t_spdb_sku");
        ignoreTableName.add("test1");
        ignoreTableName.add("undo_log");
        ignoreTableName.add("undo_log_biao");
        ignoreTableName.add("user");
        ignoreTableName.add("user_0");
        ignoreTableName.add("user_1");
        ignoreTableName.add("user_2");
        ignoreTableName.add("user_3");
        ignoreTableName.add("xxl_job_group");
        ignoreTableName.add("xxl_job_info");
        ignoreTableName.add("xxl_job_lock");
        ignoreTableName.add("xxl_job_log");
        ignoreTableName.add("xxl_job_logglue");
        ignoreTableName.add("xxl_job_registry");
        ignoreTableName.add("xxl_job_user");*/
    }

}
